#include "primitives.h"
#include <vector>
#include <cmath>
#include <gl\glew.h>


void lineCool( float x0, float y0, float x1, float y1, float width )
{
	float dx = x0-x1;
	float dy = y0-y1;

	std::vector<float> verts;

	float mag = sqrt(dx*dx+dy*dy);
	dx = dx/mag*width;
	dy = dy/mag*width;

	bool endPoints = true;
	int rot = 0;

	if( endPoints )
	{
		verts.resize(72);
		verts[0]	=	x0 - dy + dx;
		verts[1] 	=	y0 + dx + dy;
		verts[2]	=	0;
		verts[3]	=	0; // Normals
		verts[4]	=	0; // Normals
		verts[5]	=	1; // Normals
		//c[6]		=	c0;
		verts[7]	=	1;
		verts[8] 	=	0;

		verts[9]	=	x0 + dy + dx;
		verts[10] =	y0 - dx + dy;
		verts[11]	=	0;
		verts[12]	=	0; // Normals
		verts[13]	=	0; // Normals
		verts[14]	=	1; // Normals
		//c[15]		=	c0;
		verts[16]	=	1;
		verts[17] 	=	1;

		verts[18]	=	x0 - dy;
		verts[19] 	=	y0 + dx;
		verts[20]	=	0;
		verts[21]	=	0; // Normals
		verts[22]	=	0; // Normals
		verts[23]	=	1; // Normals
		//c[24]		=	c0
		verts[25]	=	0.4985f;
		verts[26] 	=	0;

		verts[27]	=	x0 + dy;
		verts[28]	=	y0 - dx;
		verts[29]	=	0;
		verts[30]	=	0; // Normals
		verts[31]	=	0; // Normals
		verts[32]	=	1; // Normals
		//c[33]		=	c0;
		verts[34]	=	0.4985f;
		verts[35]	=	1;

		verts[36]	=	x1 - dy;
		verts[37]	=	y1 + dx;
		verts[38]	=	0;
		verts[39]	=	0; // Normals
		verts[40]	=	0; // Normals
		verts[41]	=	1; // Normals
		//c[42]		=	c1
		verts[43]	=	0.5015f;
		verts[44]	=	0;

		verts[45]	=	x1 + dy;
		verts[46]	=	y1 - dx;
		verts[47]	=	0;
		verts[48]	=	0; // Normals
		verts[49]	=	0; // Normals
		verts[50]	=	1; // Normals
		//c[51]		=	c1;
		verts[52]	=	0.5015f;
		verts[53]	=	1;

		verts[54]	=	x1 - dy - dx;
		verts[55]	=	y1 + dx - dy;
		verts[56]	=	0;
		verts[57]	=	0; // Normals
		verts[58]	=	0; // Normals
		verts[59]	=	1; // Normals
		//c[60]		=	c1;
		verts[61]	=	1;
		verts[62]	=	0;

		verts[63]	=	x1 + dy - dx;
		verts[64]	=	y1 - dx - dy;
		verts[65]	=	0;
		verts[66]	=	0; // Normals
		verts[67]	=	0; // Normals
		verts[68]	=	1; // Normals
		//c[69]		=	c1
		verts[70]	=	1;
		verts[71]	=	1;
	}

	//glEnable(GL_TEXTURE_2D);

	glBegin(GL_TRIANGLE_STRIP);
	for(size_t i=0; i<verts.size()-1; i+=9)
	{
		glNormal3f( verts[i+3], verts[i+4], verts[i+5] );
		glTexCoord2f( verts[i+7], verts[i+8] );
		glVertex3f( verts[i], verts[i+1], verts[i+2] );
	}
	glEnd();
}